/**
 * 
 */
package com.quiz.dao;

import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;


/**
 * Generic Datasource for a quiz that gets a reference to the database.
 * @author Brian Boyle
 * Apr 9, 2012
 */
public class QuizDataSource {

    private SQLiteDatabase database;
    private final MySQLiteHelper dbHelper;

    public QuizDataSource(Context context) {
        dbHelper = new MySQLiteHelper(context);
    }

    public void open() throws SQLException {
        database = dbHelper.getWritableDatabase();
    }

    public void close() {
        dbHelper.close();
    }

    /**
     * @return the database
     */
    public SQLiteDatabase getDatabase() {
        if (database == null) {
            open();
        }
        return database;
    }

}
